package com.linsir.lin.controller;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linsir.config.SystemConfig;
import com.linsir.lin.dto.MetaObjectDTO;
import com.linsir.lin.service.MetaObjectService;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @ProjectName:linsir
 * @Package:com.linsir.lin.controller
 * @Title: AdminController
 * @Description: 后台所有的页面跳转，不涉及到Json数据
 * @Create:2021/5/29 10:07 by @author:Linsir
 * @Update:2021/6/4 9:54 by @author:Linsir
 * @UpdateRemark: 初始创建
 * @Version 1.0.0
 */


@Controller
@RequestMapping(value = "/admin")
public class AdminController {

    @Resource
    private SystemConfig systemConfig;




    /**
     * 后台框架页面
     * @param model
     * @return
     */
    @RequestMapping(value = "",method = {RequestMethod.GET,RequestMethod.POST})
    public String Index(Model model)
    {
        model.addAttribute(systemConfig);
        return "admin";
    }

    @RequestMapping(value = "/index",method = {RequestMethod.GET})
    public String Home(ModelMap modelMap) throws IOException {
        CloseableHttpClient client = HttpClientBuilder.create().build();
        HttpGet httpGet=new HttpGet("http://api.btstu.cn/yan/api.php?charset=utf-8&encode=json");
        HttpResponse response=client.execute(httpGet);
        String strResult = EntityUtils.toString(response.getEntity());
        ObjectMapper mapper = new ObjectMapper();
        JsonNode node=mapper.readTree(strResult);
        JsonNode title=node.get("text");
        modelMap.addAttribute("title",title);
        return "index";
    }

    @RequestMapping(value = "engineerIndex",method = {RequestMethod.GET})
    public String engineerIndex()
    {
        return "engineerIndex";
    }




    /**
     * 后台信息页面
     * @param model
     * @return
     */
    @RequestMapping(value = "/info")
    public String info(Model model)
    {
        model.addAttribute(systemConfig);
        return "info";
    }

    /**
     *
     * 基础code
     *
     */

    @RequestMapping(value ="/basecode", method = {RequestMethod.GET})
    public  String baseCode()
    {
        return "baseCode/baseCode";
    }


    /**
     * 菜单管理
     *
     */

    @RequestMapping(value = "/sysMenu",method = {RequestMethod.GET})
    public String sysMenu()
    {
        return "sysMenu/sysMenu";
    }




}
